<html>
 <head>
  <meta charset="utf-8"/>
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"/>
  <title>
   快速了解Scala技术栈  | 数螺 | NAUT IDEA
  </title>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" rel="stylesheet"/>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
  <style type="text/css">
   #xmain img {
                  max-width: 100%;
                  display: block;
                  margin-top: 10px;
                  margin-bottom: 10px;
                }

                #xmain p {
                    line-height:150%;
                    font-size: 16px;
                    margin-top: 20px;
                }

                #xmain h2 {
                    font-size: 24px;
                }

                #xmain h3 {
                    font-size: 20px;
                }

                #xmain h4 {
                    font-size: 18px;
                }


                .header {
	           background-color: #0099ff;
	           color: #ffffff;
	           margin-bottom: 20px;
	        }

	        .header p {
                  margin: 0px;
                  padding: 10px 0;
                  display: inline-block;  
                  vertical-align: middle;
                  font-size: 16px;
               }

               .header a {
                 color: white;
               }

              .header img {
                 height: 25px;
              }
  </style>
  <script src="http://cdn.bootcss.com/jquery/3.0.0/jquery.min.js">
  </script>
  <script src="http://nautstatic-10007657.file.myqcloud.com/static/css/readability.min.js" type="text/javascript">
  </script>
  <script type="text/javascript">
   $(document).ready(function() {
                 var loc = document.location;
                 var uri = {
                  spec: "http://dataunion.org/2788.html",
                  host: "http://dataunion.org",
                  prePath: "http://dataunion.org",
                  scheme: "http",
                  pathBase: "http://dataunion.org/"
                 };
    
                 var documentClone = document.cloneNode(true);
                 var article = new Readability(uri, documentClone).parse();
     
                 document.getElementById("xmain").innerHTML = article.content;
                });
  </script>
  <!-- 1466458618: Accept with keywords: (title(0.0):栈,社区,技术,数盟, topn(0.333333333333):社区,语言,队列,Hadoop,特性,程序员,测试工具,工具,定义,模型,技术,基础架构,分布式系统,数据处理,Spark,数据,服务端,场景,函数,项目,性能,文章,数盟,语法,风格,客户端,编程语言,框架,消息,分布式).-->
 </head>
 <body onload="">
  <div class="header">
   <div class="container">
    <div class="row">
     <div class="col-xs-6 col-sm-6 text-left">
      <a href="/databee">
       <img src="http://nautidea-10007657.cos.myqcloud.com/logo_white.png"/>
      </a>
      <a href="/databee">
       <p>
        数螺
       </p>
      </a>
     </div>
     <div class="hidden-xs col-sm-6 text-right">
      <p>
       致力于数据科学的推广和知识传播
      </p>
     </div>
    </div>
   </div>
  </div>
  <div class="container text-center">
   <h1>
    快速了解Scala技术栈
   </h1>
  </div>
  <div class="container" id="xmain">
   ﻿﻿
   <title>
    快速了解Scala技术栈 | 数盟社区
   </title>
   <!-- All in One SEO Pack 2.2.7.6.2 by Michael Torbert of Semper Fi Web Design[32,59] -->
   <!-- /all in one seo pack -->
   <!--
<div align="center">
<a href="http://strata.oreilly.com.cn/hadoop-big-data-cn?cmp=mp-data-confreg-home-stcn16_dataunion_pc" target="_blank"><img src="http://dataunion.org/wp-content/uploads/2016/05/stratabj.jpg"/ ></a>
</div>
-->
   <header id="header-web">
    <div class="header-main">
     <hgroup class="logo">
      <h1>
       <a href="http://dataunion.org/" rel="home" title="数盟社区">
        <img src="http://dataunion.org/wp-content/themes/yzipi/images/logo.png"/>
       </a>
      </h1>
     </hgroup>
     <!--logo-->
     <nav class="header-nav">
      <ul class="menu" id="menu-%e4%b8%bb%e8%8f%9c%e5%8d%95">
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-71" id="menu-item-71">
        <a href="http://dataunion.org/category/events" title="events">
         活动
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-22457" id="menu-item-22457">
          <a href="http://dataunion.org/2016timeline">
           2016档期
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-22459" id="menu-item-22459">
          <a href="http://dataunion.org/category/parterc">
           合作会议
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category current-post-ancestor menu-item-has-children menu-item-20869" id="menu-item-20869">
        <a href="http://dataunion.org/category/tech" title="articles">
         文章
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category current-post-ancestor current-menu-parent current-post-parent menu-item-20867" id="menu-item-20867">
          <a href="http://dataunion.org/category/tech/base" title="base">
           基础架构
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3302" id="menu-item-3302">
          <a href="http://dataunion.org/category/tech/ai" title="ai">
           人工智能
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3303" id="menu-item-3303">
          <a href="http://dataunion.org/category/tech/analysis" title="analysis">
           数据分析
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21920" id="menu-item-21920">
          <a href="http://dataunion.org/category/tech/dm">
           数据挖掘
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3314" id="menu-item-3314">
          <a href="http://dataunion.org/category/tech/viz" title="viz">
           可视化
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category current-post-ancestor current-menu-parent current-post-parent menu-item-3305" id="menu-item-3305">
          <a href="http://dataunion.org/category/tech/devl" title="devl">
           编程语言
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-20876" id="menu-item-20876">
        <a href="http://dataunion.org/category/industry">
         行业
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-16328" id="menu-item-16328">
          <a href="http://dataunion.org/category/industry/case" title="case">
           行业应用
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-2112" id="menu-item-2112">
          <a href="http://dataunion.org/category/industry/demo" title="demo">
           Demo展示
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21562" id="menu-item-21562">
          <a href="http://dataunion.org/category/industry/news">
           行业资讯
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-311" id="menu-item-311">
        <a href="http://dataunion.org/category/sources" title="sources">
         资源
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20870" id="menu-item-20870">
        <a href="http://dataunion.org/category/books" title="book">
         图书
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21363" id="menu-item-21363">
        <a href="http://dataunion.org/category/training">
         课程
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-21853" id="menu-item-21853">
        <a href="http://dataunion.org/category/jobs">
         职位
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-22050" id="menu-item-22050">
          <a href="http://dataunion.org/category/career">
           职业规划
          </a>
         </li>
        </ul>
       </li>
      </ul>
     </nav>
     <!--header-nav-->
    </div>
   </header>
   <!--header-web-->
   <div id="main">
    <div id="soutab">
     <form action="http://dataunion.org/" class="search" method="get">
     </form>
    </div>
    <div id="container">
     <nav id="mbx">
      当前位置：
      <a href="http://dataunion.org">
       首页
      </a>
      &gt;
      <a href="http://dataunion.org/category/tech">
       文章
      </a>
      &gt;
      <a href="http://dataunion.org/category/tech/base">
       基础架构
      </a>
      &gt;  正文
     </nav>
     <!--mbx-->
     <article class="content">
      <header align="centre" class="contenttitle">
       <div class="mscc">
        <h1 class="mscctitle">
         <a href="http://dataunion.org/2788.html">
          快速了解Scala技术栈
         </a>
        </h1>
        <address class="msccaddress ">
         <em>
          3,343 次阅读 -
         </em>
         <a href="http://dataunion.org/category/tech/base" rel="category tag">
          基础架构
         </a>
         ,
         <a href="http://dataunion.org/category/tech/devl" rel="category tag">
          编程语言
         </a>
        </address>
       </div>
      </header>
      <div class="content-text">
       <div align="left">
        <h4>
         作者
         <a class="editorlink f_taxonomyEditor" href="http://www.infoq.com/cn/author/%E5%BC%A0%E9%80%B8">
          张逸
         </a>
        </h4>
       </div>
       <div align="left">
        <p>
         我无可救药地成为了Scala的超级粉丝。在我使用Scala开发项目以及编写框架后，它就仿佛凝聚成为一个巨大的黑洞，吸引力使我不得不飞向它，以至于开始背离Java。固然Java 8为Java阵营增添了一丝亮色，却是望眼欲穿，千呼万唤始出来。而Scala程序员，却早就在享受lambda、高阶函数、trait、隐式转换等带来的福利了。
        </p>
        <p>
         Java像是一头史前巨兽，它在OO的方向上几乎走到了极致，硬将它拉入FP阵营，确乎有些强人所难了。而Scala则不，因为它的诞生就是OO与FP的混血儿——完美的基因融合。
        </p>
        <p>
         “Object-Oriented Meets Functional”，这是Scala语言官方网站上飘扬的旗帜。这也是Scala的野心，当然，也是Martin Odersky的雄心。
        </p>
        <h2>
         <strong>
          Scala社区的发展
         </strong>
        </h2>
        <p>
         然而，一门语言并不能孤立地存在，必须提供依附的平台，以及围绕它建立的生态圈。不如此，语言则不足以壮大。Ruby很优秀，但如果没有Ruby On Rails的推动，也很难发展到今天这个地步。Scala同样如此。反过来，当我们在使用一门语言时，也要选择符合这门语言的技术栈，在整个生态圈中找到适合具体场景的框架或工具。
        </p>
        <p>
         当然，我们在使用Scala进行软件开发时，亦可以寻求庞大的Java社区支持；可是，如果选择调用Java开发的库，就会牺牲掉Scala给我们带来的福利。幸运的是，在如今，多数情况你已不必如此。伴随着Scala语言逐渐形成的Scala社区，已经开始慢慢形成相对完整的Scala技术栈。无论是企业开发、自动化测试或者大数据领域，这些框架或工具已经非常完整地呈现了Scala开发的生态系统。
        </p>
        <h2>
         <strong>
          快速了解Scala技术栈
         </strong>
        </h2>
        <p>
         若要了解Scala技术栈，并快速学习这些框架，一个好的方法是下载typesafe推出的Activator。它提供了相对富足的基于Scala以及Scala主流框架的开发模板，这其中实则还隐含了typesafe为Scala开发提供的最佳实践与指导。下图是Activator模板的截图：
        </p>
        <div id="lowerFullwidthVCR">
        </div>
        <p>
         <img src="http://cdn3.infoqstatic.com/resource/articles/scala-technology/zh/resources/0828010.png"/>
        </p>
        <p>
         那么，是否有渠道可以整体地获知Scala技术栈到底包括哪些框架或工具，以及它们的特性与使用场景呢？感谢Lauris Dzilums以及其他在Github的Contributors。在Lauris Dzilums的Github上，他建立了名为awesome-scala的
         <a href="https://github.com/lauris/awesome-scala">
          Repository
         </a>
         ，搜罗了当下主要的基于Scala开发的框架与工具，涉及到的领域包括：
        </p>
        <ul>
         <li>
          Database
         </li>
         <li>
          Web Frameworks
         </li>
         <li>
          i18n
         </li>
         <li>
          Authentication
         </li>
         <li>
          Testing
         </li>
         <li>
          JSON Manipulation
         </li>
         <li>
          Serialization
         </li>
         <li>
          Science and Data Analysis
         </li>
         <li>
          Big Data
         </li>
         <li>
          Functional Reactive Programming
         </li>
         <li>
          Modularization and Dependency Injection
         </li>
         <li>
          Distributed Systems
         </li>
         <li>
          Extensions
         </li>
         <li>
          Android
         </li>
         <li>
          HTTP
         </li>
         <li>
          Semantic Web
         </li>
         <li>
          Metrics and Monitoring
         </li>
         <li>
          Sbt plugins
         </li>
        </ul>
        <p>
         是否有“乱花渐欲迷人眼”的感觉？不是太少，而是太多！那就让我删繁就简，就我的经验介绍一些框架或工具，从持久化、分布式系统、HTTP、Web框架、大数据、测试这六方面入手，作一次蜻蜓点水般的俯瞰。
        </p>
        <h2>
         持久化
        </h2>
        <p>
         归根结底，对数据的持久化主要还是通过JDBC访问数据库。但是，我们需要更好的API接口，能更好地与Scala契合，又或者更自然的ORM。如果希望执行SQL语句来操作数据库，那么运用相对广泛的是框架ScalikeJDBC，它提供了非常简单的API接口，甚至提供了SQL的DSL语法。例如：
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-576861e76cf60350206260" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           val alice: Option[Member] = withSQL {
    select.from(Member as m).where.eq(m.name, name)
  }.map(rs =&amp;gt; Member(rs)).single.apply()
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-576861e76cf60350206260-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf60350206260-2">
                2
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf60350206260-3">
                3
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-576861e76cf60350206260-1">
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 val
                </span>
                <span class="crayon-v">
                 alice
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 Option
                </span>
                <span class="crayon-sy">
                 [
                </span>
                <span class="crayon-v">
                 Member
                </span>
                <span class="crayon-sy">
                 ]
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 withSQL
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf60350206260-2">
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 select
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-e">
                 from
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-e">
                 Member
                </span>
                <span class="crayon-st">
                 as
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 m
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 where
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-e">
                 eq
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 m
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 name
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 name
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cf60350206260-3">
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 }
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-e">
                 map
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 rs
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =&amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 Member
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 rs
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 single
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-e">
                 apply
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0023 seconds] -->
        <p>
         如果希望使用ORM框架，Squeryl应该是很好的选择。我的同事杨云在项目中使用过该框架，体验不错。该框架目前的版本为0.9.5，已经比较成熟了。Squeryl支持按惯例映射对象与关系表，相当于定义一个POSO（Plain Old Scala Object），从而减少框架的侵入。若映射违背了惯例，则可以利用框架定义的annotation如@Column定义映射。框架提供了org.squeryl.Table[T]来完成这种映射关系。
        </p>
        <p>
         因为可以运用Scala的高阶函数、偏函数等特性，使得Squeryl的语法非常自然，例如根据条件对表进行更新：
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-576861e76cf72667798686" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           update(songs)(s =&amp;gt;
  where(s.title === "Watermelon Man")
  set(s.title := "The Watermelon Man",
      s.year  := s.year.~ + 1)
)
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-576861e76cf72667798686-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf72667798686-2">
                2
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf72667798686-3">
                3
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf72667798686-4">
                4
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf72667798686-5">
                5
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-576861e76cf72667798686-1">
                <span class="crayon-e">
                 update
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 songs
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 s
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =&amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf72667798686-2">
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 where
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 s
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 title
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 ===
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-s">
                 "Watermelon Man"
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cf72667798686-3">
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 set
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 s
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 title
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-s">
                 "The Watermelon Man"
                </span>
                <span class="crayon-sy">
                 ,
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf72667798686-4">
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 s
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 year
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 s
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 year
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-o">
                 ~
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 +
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 1
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cf72667798686-5">
                <span class="crayon-sy">
                 )
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0143 seconds] -->
        <p>
        </p>
        <h2>
         分布式系统
        </h2>
        <p>
         我放弃介绍诸如模块化管理以及依赖注入，是因为它们在Scala社区的价值不如Java社区大。例如，我们可以灵活地运用trait结合cake pattern就可以实现依赖注入的特性。因此，我直接跳过这些内容，来介绍影响更大的支持分布式系统的框架。
        </p>
        <p>
         Finagle的血统高贵，来自过去的寒门，现在的高门大族Twitter。Twitter是较早使用Scala作为服务端开发的互联网公司，因而积累了非常多的Scala经验，并基于这些经验推出了一些颇有影响力的框架。由于Twitter对可伸缩性、性能、并发的高要求，这些框架也极为关注这些质量属性。Finagle就是其中之一。它是一个扩展的RPC系统，以支持高并发服务器的搭建。我并没有真正在项目中使用过Finagle，大家可以到它的官方网站获得更多消息。
        </p>
        <p>
         对于分布式的支持，绝对绕不开的框架还是AKKA。它产生的影响力如此之大，甚至使得Scala语言从2.10开始，就放弃了自己的Actor模型，转而将AKKA Actor收编为2.10版本的语言特性。许多框架在分布式处理方面也选择了使用AKKA，例如Spark、Spray。AKKA的Actor模型参考了Erlang语言，为每个Actor提供了一个专有的Mailbox，并将消息处理的实现细节做了良好的封装，使得并发编程变得更加容易。AKKA很好地统一了本地Actor与远程Actor，提供了几乎一致的API接口。AKKA也能够很好地支持消息的容错，除了提供一套完整的Monitoring机制外，还提供了对Dead Letter的处理。
        </p>
        <p>
         AKKA天生支持EDA（Event-Driven Architecture）。当我们针对领域建模时，可以考虑针对事件进行建模。在AKKA中，这些事件模型可以被定义为Scala的case class，并作为消息传递给Actor。借用Vaughn Vernon在《实现领域驱动设计》中的例子，针对如下的事件流：
        </p>
        <p>
         <img src="http://cdn3.infoqstatic.com/resource/articles/scala-technology/zh/resources/0828011.png"/>
        </p>
        <p>
         我们可以利用Akka简单地实现：
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-576861e76cf7b414042937" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           case class AllPhoneNumberListed(phoneNumbers: List[Int])
case class PhoneNumberMatched(phoneNumbers: List[Int])
case class AllPhoneNumberRead(fileName: String)

class PhoneNumbersPublisher(actor: ActorRef) extends ActorRef {
	def receive = {
		case ReadPhoneNumbers =&amp;gt;
		//list phone numbers

		actor ! AllPhoneNumberListed(List(1110, ))
	}
}

class PhoneNumberFinder(actor: ActorRef) extends ActorRef {
	def receive = {
		case AllPhoneNumberListed(numbers) =&amp;gt; 
			//match

			actor ! PhoneNumberMatched()
	}
}

val finder = system.actorOf(Prop(new PhoneNumberFinder(...)))
val publisher = system.actorOf(Prop(new PhoneNumbersPublisher(finder)))

publisher ! ReadPhoneNumbers("callinfo.txt")
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-576861e76cf7b414042937-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf7b414042937-2">
                2
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf7b414042937-3">
                3
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf7b414042937-4">
                4
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf7b414042937-5">
                5
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf7b414042937-6">
                6
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf7b414042937-7">
                7
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf7b414042937-8">
                8
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf7b414042937-9">
                9
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf7b414042937-10">
                10
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf7b414042937-11">
                11
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf7b414042937-12">
                12
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf7b414042937-13">
                13
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf7b414042937-14">
                14
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf7b414042937-15">
                15
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf7b414042937-16">
                16
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf7b414042937-17">
                17
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf7b414042937-18">
                18
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf7b414042937-19">
                19
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf7b414042937-20">
                20
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf7b414042937-21">
                21
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf7b414042937-22">
                22
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf7b414042937-23">
                23
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf7b414042937-24">
                24
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf7b414042937-25">
                25
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf7b414042937-26">
                26
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-576861e76cf7b414042937-1">
                <span class="crayon-st">
                 case
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-t">
                 class
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 AllPhoneNumberListed
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 phoneNumbers
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 List
                </span>
                <span class="crayon-sy">
                 [
                </span>
                <span class="crayon-t">
                 Int
                </span>
                <span class="crayon-sy">
                 ]
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf7b414042937-2">
                <span class="crayon-st">
                 case
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-t">
                 class
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 PhoneNumberMatched
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 phoneNumbers
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 List
                </span>
                <span class="crayon-sy">
                 [
                </span>
                <span class="crayon-t">
                 Int
                </span>
                <span class="crayon-sy">
                 ]
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cf7b414042937-3">
                <span class="crayon-st">
                 case
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-t">
                 class
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 AllPhoneNumberRead
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 fileName
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-t">
                 String
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf7b414042937-4">
               </div>
               <div class="crayon-line" id="crayon-576861e76cf7b414042937-5">
                <span class="crayon-t">
                 class
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 PhoneNumbersPublisher
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 actor
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 ActorRef
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-r">
                 extends
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 ActorRef
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf7b414042937-6">
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-v">
                 receive
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cf7b414042937-7">
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 case
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 ReadPhoneNumbers
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =&amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf7b414042937-8">
                <span class="crayon-h">
                </span>
                <span class="crayon-c">
                 //list phone numbers
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cf7b414042937-9">
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf7b414042937-10">
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 actor
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 !
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 AllPhoneNumberListed
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-e">
                 List
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-cn">
                 1110
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cf7b414042937-11">
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 }
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf7b414042937-12">
                <span class="crayon-sy">
                 }
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cf7b414042937-13">
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf7b414042937-14">
                <span class="crayon-t">
                 class
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 PhoneNumberFinder
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 actor
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 ActorRef
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-r">
                 extends
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 ActorRef
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cf7b414042937-15">
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-v">
                 receive
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf7b414042937-16">
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 case
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 AllPhoneNumberListed
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 numbers
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =&amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cf7b414042937-17">
                <span class="crayon-h">
                </span>
                <span class="crayon-c">
                 //match
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf7b414042937-18">
               </div>
               <div class="crayon-line" id="crayon-576861e76cf7b414042937-19">
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 actor
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 !
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 PhoneNumberMatched
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf7b414042937-20">
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 }
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cf7b414042937-21">
                <span class="crayon-sy">
                 }
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf7b414042937-22">
               </div>
               <div class="crayon-line" id="crayon-576861e76cf7b414042937-23">
                <span class="crayon-e">
                 val
                </span>
                <span class="crayon-v">
                 finder
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 system
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-e">
                 actorOf
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-e">
                 Prop
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-r">
                 new
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 PhoneNumberFinder
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf7b414042937-24">
                <span class="crayon-e">
                 val
                </span>
                <span class="crayon-v">
                 publisher
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 system
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-e">
                 actorOf
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-e">
                 Prop
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-r">
                 new
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 PhoneNumbersPublisher
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 finder
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cf7b414042937-25">
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf7b414042937-26">
                <span class="crayon-v">
                 publisher
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 !
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 ReadPhoneNumbers
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-s">
                 "callinfo.txt"
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0107 seconds] -->
        <p>
         若需要处理的电话号码数据量大，我们可以很容易地将诸如PhoneNumbersPublisher、PhoneNumberFinder等Actors部署为Remote Actor。此时，仅仅需要更改客户端获得Actor的方式即可。
        </p>
        <p>
         Twitter实现的Finagle是针对RPC通信，Akka则提供了内部的消息队列（MailBox），而由LinkedIn主持开发的Kafka则提供了支持高吞吐量的分布式消息队列中间件。这个顶着文学家帽子的消息队列，能够支持高效的Publisher-Subscriber模式进行消息处理，并以快速、稳定、可伸缩的特性很快引起了开发者的关注，并在一些框架中被列入候选的消息队列而提供支持，例如，Spark Streaming就支持Kafka作为流数据的Input Source。
        </p>
        <h2>
         HTTP
        </h2>
        <p>
         严格意义上讲，Spray并非单纯的HTTP框架，它还支持REST、JSON、Caching、Routing、IO等功能。Spray的模块及其之间的关系如下图所示：
        </p>
        <p>
         <img src="http://cdn3.infoqstatic.com/resource/articles/scala-technology/zh/resources/0828012.png"/>
        </p>
        <p>
         我在项目中主要将Spray作为REST框架来使用，并结合AKKA来处理领域逻辑。Spray处理HTTP请求的架构如下图所示：
        </p>
        <p>
         <img src="http://cdn3.infoqstatic.com/resource/articles/scala-technology/zh/resources/0828014.png"/>
        </p>
        <p>
         Spray提供了一套DSL风格的path语法，能够非常容易地编写支持各种HTTP动词的请求，例如：
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-576861e76cf84943919005" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           trait HttpServiceBase extends Directives with Json4sSupport {
     implicit val system: ActorSystem
     implicit def json4sFormats: Formats = DefaultFormats
     def route: Route
}

trait CustomerService extends HttpServiceBase {
     val route = 
          path("customer" / "groups") {
               get {
                    parameters('groupids.?) {
                         (groupids) =&amp;gt;
                              complete {
                                   groupids match {
                                        case Some(groupIds) =&amp;gt; 
                    ViewUserGroup.queryUserGroup(groupIds.split(",").toList)
                                        case None =&amp;gt; ViewUserGroup.queryUserGroup()
                                   }
                              }
                    }
               }
          } ~
          path("customers" / "vip" / "failureinfo") {
               post {
                    entity(as[FailureVipCustomerRequest]) {
                         request =&amp;gt; 
                              complete {
                                   VipCustomer.failureInfo(request) 
                              }
                    }
               }
          }
}
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-576861e76cf84943919005-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf84943919005-2">
                2
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf84943919005-3">
                3
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf84943919005-4">
                4
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf84943919005-5">
                5
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf84943919005-6">
                6
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf84943919005-7">
                7
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf84943919005-8">
                8
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf84943919005-9">
                9
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf84943919005-10">
                10
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf84943919005-11">
                11
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf84943919005-12">
                12
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf84943919005-13">
                13
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf84943919005-14">
                14
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf84943919005-15">
                15
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf84943919005-16">
                16
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf84943919005-17">
                17
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf84943919005-18">
                18
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf84943919005-19">
                19
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf84943919005-20">
                20
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf84943919005-21">
                21
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf84943919005-22">
                22
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf84943919005-23">
                23
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf84943919005-24">
                24
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf84943919005-25">
                25
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf84943919005-26">
                26
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf84943919005-27">
                27
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf84943919005-28">
                28
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf84943919005-29">
                29
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf84943919005-30">
                30
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf84943919005-31">
                31
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf84943919005-32">
                32
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf84943919005-33">
                33
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-576861e76cf84943919005-1">
                <span class="crayon-e">
                 trait
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 HttpServiceBase
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-r">
                 extends
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 Directives
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 with
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 Json4sSupport
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf84943919005-2">
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 implicit
                </span>
                <span class="crayon-e">
                 val
                </span>
                <span class="crayon-v">
                 system
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 ActorSystem
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cf84943919005-3">
                <span class="crayon-e">
                </span>
                <span class="crayon-e">
                 implicit
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-v">
                 json4sFormats
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 Formats
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 DefaultFormats
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf84943919005-4">
                <span class="crayon-e">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-v">
                 route
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-i">
                 Route
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cf84943919005-5">
                <span class="crayon-sy">
                 }
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf84943919005-6">
               </div>
               <div class="crayon-line" id="crayon-576861e76cf84943919005-7">
                <span class="crayon-e">
                 trait
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 CustomerService
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-r">
                 extends
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 HttpServiceBase
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf84943919005-8">
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 val
                </span>
                <span class="crayon-v">
                 route
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cf84943919005-9">
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 path
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-s">
                 "customer"
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 /
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-s">
                 "groups"
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf84943919005-10">
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 get
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cf84943919005-11">
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 parameters
                </span>
                <span class="crayon-sy">
                 (
                </span>
                '
                <span class="crayon-v">
                 groupids
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 ?
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf84943919005-12">
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 groupids
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =&amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cf84943919005-13">
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 complete
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf84943919005-14">
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 groupids
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 match
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cf84943919005-15">
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 case
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 Some
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 groupIds
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =&amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf84943919005-16">
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 ViewUserGroup
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-e">
                 queryUserGroup
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 groupIds
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-e">
                 split
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-s">
                 ","
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 toList
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cf84943919005-17">
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 case
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 None
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =&amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 ViewUserGroup
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-e">
                 queryUserGroup
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf84943919005-18">
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 }
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cf84943919005-19">
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 }
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf84943919005-20">
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 }
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cf84943919005-21">
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 }
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf84943919005-22">
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 }
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 ~
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cf84943919005-23">
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 path
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-s">
                 "customers"
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 /
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-s">
                 "vip"
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 /
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-s">
                 "failureinfo"
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf84943919005-24">
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 post
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cf84943919005-25">
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 entity
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-st">
                 as
                </span>
                <span class="crayon-sy">
                 [
                </span>
                <span class="crayon-v">
                 FailureVipCustomerRequest
                </span>
                <span class="crayon-sy">
                 ]
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf84943919005-26">
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 request
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =&amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cf84943919005-27">
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 complete
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf84943919005-28">
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 VipCustomer
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-e">
                 failureInfo
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 request
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cf84943919005-29">
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 }
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf84943919005-30">
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 }
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cf84943919005-31">
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 }
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf84943919005-32">
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 }
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cf84943919005-33">
                <span class="crayon-sy">
                 }
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0135 seconds] -->
        <p>
         我个人认为，在进行Web开发时，完全可以放弃Web框架，直接选择AngularJS结合Spray和AKKA，同样能够很好地满足Web开发需要。
        </p>
        <p>
         Spray支持REST，且Spray自身提供了服务容器spray-can，因而允许Standalone的部署（当然也支持部署到Jetty和tomcat等应用服务器）。Spray对HTTP请求的内部处理机制实则是基于Akka-IO，通过IO这个Actor发出对HTTP的bind消息。例如：
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-576861e76cf8c279939327" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           IO(Http) ! Http.Bind(service, interface = "0.0.0.0", port = 8889)
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-576861e76cf8c279939327-1">
                1
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-576861e76cf8c279939327-1">
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 IO
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 Http
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 !
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 Http
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-e">
                 Bind
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 service
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-t">
                 interface
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-s">
                 "0.0.0.0"
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 port
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 8889
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0014 seconds] -->
        <p>
         我们可以编写不同的Boot对象去绑定不同的主机Host以及端口。这些特性都使得Spray能够很好地支持当下较为流行的Micro Service架构风格。
        </p>
        <h2>
         Web框架
        </h2>
        <p>
         正如前面所说，当我们选择Spray作为REST框架时，完全可以选择诸如AngularJS或者Backbone之类的JavaScript框架开发Web客户端。客户端能够处理自己的逻辑，然后再以JSON格式发送请求给REST服务端。这时，我们将模型视为资源（Resource），视图完全在客户端。JS的控制器负责控制客户端的界面逻辑，服务端的控制器则负责处理业务逻辑，于是传统的MVC就变化为VC+R+C模式。这里的R指的是Resource，而服务端与客户端则通过JSON格式的Resource进行通信。
        </p>
        <p>
         若硬要使用专有的Web框架，在Scala技术栈下，最为流行的就是Play Framework，这是一个标准的MVC框架。另外一个相对小众的Web框架是Lift。它与大多数Web框架如RoR、Struts、Django以及Spring MVC、Play不同，采用的并非MVC模式，而是使用了所谓的View First。它驱动开发者对内容生成与内容展现（Markup）形成“关注点分离”。
        </p>
        <p>
         Lift将关注点重点放在View上，这是因为在一些Web应用中，可能存在多个页面对同一种Model的Action。倘若采用MVC中的Controller，会使得控制变得非常复杂。Lift提出了一种所谓view-snippet-model（简称为VSM）的模式。
        </p>
        <p>
         <img src="http://cdn3.infoqstatic.com/resource/articles/scala-technology/zh/resources/0828015.png"/>
        </p>
        <p>
         View主要为响应页面请求的HTML内容，分为template views和generated views。Snippet的职责则用于生成动态内容，并在模型发生更改时，对Model和View进行协调。
        </p>
        <h2>
         大数据
        </h2>
        <p>
         大数据框架最耀眼的新星非Spark莫属。与许多专有的大数据处理平台不同，Spark建立在统一抽象的RDD之上，使得它可以以基本一致的方式应对不同的大数据处理场景，包括MapReduce，Streaming，SQL，Machine Learning以及Graph等。这即Matei Zaharia所谓的“设计一个通用的编程抽象（Unified Programming Abstraction）。
        </p>
        <p>
         <img src="http://cdn3.infoqstatic.com/resource/articles/scala-technology/zh/resources/0828016.jpg"/>
        </p>
        <p>
         由于Spark具有先进的DAG执行引擎，支持cyclic data flow和内存计算。因此相比较Hadoop而言，性能更优。在内存中它的运行速度是Hadoop MapReduce的100倍，在磁盘中是10倍。
        </p>
        <p>
         由于使用了Scala语言，通过高效利用Scala的语言特性，使得Spark的总代码量出奇地少，性能却在多数方面都具备一定的优势（只有在Streaming方面，逊色于Storm）。下图是针对Spark 0.9版本的BenchMark：
        </p>
        <p>
         <img src="http://cdn3.infoqstatic.com/resource/articles/scala-technology/zh/resources/0828017.png"/>
        </p>
        <p>
         由于使用了Scala，使得语言的函数式特性得到了最棒的利用。事实上，函数式语言的诸多特性包括不变性、无副作用、组合子等，天生与数据处理匹配。于是，针对WordCount，我们可以如此简易地实现：
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-576861e76cf98980307919" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           file = spark.textFile("hdfs://...")

file.flatMap(line =&amp;gt; line.split(" "))
    .map(word =&amp;gt; (word, 1))
    .reduceByKey(_ + _)
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-576861e76cf98980307919-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf98980307919-2">
                2
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf98980307919-3">
                3
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cf98980307919-4">
                4
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cf98980307919-5">
                5
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-576861e76cf98980307919-1">
                <span class="crayon-v">
                 file
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 spark
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-e">
                 textFile
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-s">
                 "hdfs://..."
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf98980307919-2">
               </div>
               <div class="crayon-line" id="crayon-576861e76cf98980307919-3">
                <span class="crayon-v">
                 file
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-e">
                 flatMap
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 line
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =&amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 line
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-e">
                 split
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-s">
                 " "
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cf98980307919-4">
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-e">
                 map
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-t">
                 word
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =&amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-t">
                 word
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 1
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cf98980307919-5">
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-e">
                 reduceByKey
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 _
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 +
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 _
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0106 seconds] -->
        <p>
         要是使用Hadoop，就没有这么方便了。幸运的是，Twitter的一个开源框架scalding提供了对Hadoop MapReduce的抽象与包装。它使得我们可以按照Scala的方式执行MapReduce的Job：
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-576861e76cfa0678803288" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           class WordCountJob(args : Args) extends Job(args) {
  TextLine( args("input") )
    .flatMap('line -&amp;gt; 'word) { line : String =&amp;gt; tokenize(line) }
    .groupBy('word) { _.size }
    .write( Tsv( args("output") ) )

  // Split a piece of text into individual words.
  def tokenize(text : String) : Array[String] = {
    // Lowercase each word and remove punctuation.
    text.toLowerCase.replaceAll("[^a-zA-Z0-9\\s]", "").split("\\s+")
  }
}
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-576861e76cfa0678803288-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cfa0678803288-2">
                2
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cfa0678803288-3">
                3
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cfa0678803288-4">
                4
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cfa0678803288-5">
                5
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cfa0678803288-6">
                6
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cfa0678803288-7">
                7
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cfa0678803288-8">
                8
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cfa0678803288-9">
                9
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cfa0678803288-10">
                10
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cfa0678803288-11">
                11
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cfa0678803288-12">
                12
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-576861e76cfa0678803288-1">
                <span class="crayon-t">
                 class
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 WordCountJob
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 args
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 Args
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-r">
                 extends
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 Job
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 args
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cfa0678803288-2">
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 TextLine
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 args
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-s">
                 "input"
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cfa0678803288-3">
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-e">
                 flatMap
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-s">
                 'line -&amp;gt; '
                </span>
                <span class="crayon-t">
                 word
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 line
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-t">
                 String
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =&amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 tokenize
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 line
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 }
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cfa0678803288-4">
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-e">
                 groupBy
                </span>
                <span class="crayon-sy">
                 (
                </span>
                '
                <span class="crayon-t">
                 word
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 _
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-i">
                 size
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 }
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cfa0678803288-5">
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-e">
                 write
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 Tsv
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 args
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-s">
                 "output"
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cfa0678803288-6">
               </div>
               <div class="crayon-line" id="crayon-576861e76cfa0678803288-7">
                <span class="crayon-h">
                </span>
                <span class="crayon-c">
                 // Split a piece of text into individual words.
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cfa0678803288-8">
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 tokenize
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 text
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-t">
                 String
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-t">
                 Array
                </span>
                <span class="crayon-sy">
                 [
                </span>
                <span class="crayon-t">
                 String
                </span>
                <span class="crayon-sy">
                 ]
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cfa0678803288-9">
                <span class="crayon-h">
                </span>
                <span class="crayon-c">
                 // Lowercase each word and remove punctuation.
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cfa0678803288-10">
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 text
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 toLowerCase
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-e">
                 replaceAll
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-s">
                 "[^a-zA-Z0-9\\s]"
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-s">
                 ""
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-e">
                 split
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-s">
                 "\\s+"
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cfa0678803288-11">
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 }
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cfa0678803288-12">
                <span class="crayon-sy">
                 }
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0074 seconds] -->
        <p>
        </p>
        <h2>
         测试
        </h2>
        <p>
         虽然我们可以使用诸如JUnit、TestNG为Scala项目开发编写单元测试，使用Cocumber之类的BDD框架编写验收测试。但在多数情况下，我们更倾向于选择使用ScalaTest或者Specs2。在一些Java开发项目中，我们也开始尝试使用ScalaTest来编写验收测试，乃至于单元测试。
        </p>
        <p>
         若要我选择ScalaTest或Specs2，我更倾向于ScalaTest，这是因为ScalaTest支持的风格更具备多样性，可以满足各种不同的需求，例如传统的JUnit风格、函数式风格以及Spec方式。我的一篇博客《
         <a href="http://agiledon.github.io/blog/2014/01/13/testing-styles-of-scalatest/">
          ScalaTest的测试风格
         </a>
         》详细介绍了各自的语法。
        </p>
        <p>
         一个被广泛使用的测试工具是Gatling，它是基于Scala、AKKA以及Netty开发的性能测试与压力测试工具。我的同事刘冉在InfoQ发表的文章《
         <a href="http://www.infoq.com/cn/articles/new-generation-server-testing-tool-gatling">
          新一代服务器性能测试工具Gatling
         </a>
         》对Gatling进行了详细深入的介绍。
        </p>
        <p>
         ScalaMeter也是一款很不错的性能测试工具。我们可以像编写ScalaTest测试那样的风格来编写ScalaMeter性能测试用例，并能够快捷地生成性能测试数据。这些功能都非常有助于我们针对代码或软件产品进行BenchMark测试。我们曾经用ScalaMeter来编写针对Scala集合的性能测试，例如比较Vector、ArrayBuffer、ListBuffer以及List等集合的相关操作，以便于我们更好地使用Scala集合。以下代码展示了如何使用ScalaMeter编写性能测试：
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-576861e76cfa8020315317" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           import org.scalameter.api._

object RangeBenchmark
extends PerformanceTest.Microbenchmark {
  val ranges = for {
    size &amp;lt;- Gen.range("size")(300000, 1500000, 300000)
  } yield 0 until size

  measure method "map" in {
    using(ranges) curve("Range") in {
      _.map(_ + 1)
    }
  }
}
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-576861e76cfa8020315317-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cfa8020315317-2">
                2
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cfa8020315317-3">
                3
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cfa8020315317-4">
                4
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cfa8020315317-5">
                5
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cfa8020315317-6">
                6
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cfa8020315317-7">
                7
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cfa8020315317-8">
                8
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cfa8020315317-9">
                9
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cfa8020315317-10">
                10
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cfa8020315317-11">
                11
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cfa8020315317-12">
                12
               </div>
               <div class="crayon-num" data-line="crayon-576861e76cfa8020315317-13">
                13
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-576861e76cfa8020315317-14">
                14
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-576861e76cfa8020315317-1">
                <span class="crayon-e">
                 import
                </span>
                <span class="crayon-v">
                 org
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 scalameter
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 api
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-i">
                 _
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cfa8020315317-2">
               </div>
               <div class="crayon-line" id="crayon-576861e76cfa8020315317-3">
                <span class="crayon-t">
                 object
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 RangeBenchmark
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cfa8020315317-4">
                <span class="crayon-r">
                 extends
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 PerformanceTest
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-i">
                 Microbenchmark
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cfa8020315317-5">
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 val
                </span>
                <span class="crayon-v">
                 ranges
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 for
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cfa8020315317-6">
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 size
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 lt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 -
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 Gen
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-e">
                 range
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-s">
                 "size"
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-cn">
                 300000
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 1500000
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 300000
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cfa8020315317-7">
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 }
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-i">
                 yield
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 0
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 until
                </span>
                <span class="crayon-e">
                 size
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cfa8020315317-8">
               </div>
               <div class="crayon-line" id="crayon-576861e76cfa8020315317-9">
                <span class="crayon-e">
                </span>
                <span class="crayon-e">
                 measure
                </span>
                <span class="crayon-i">
                 method
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-s">
                 "map"
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 in
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cfa8020315317-10">
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 using
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 ranges
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 curve
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-s">
                 "Range"
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 in
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cfa8020315317-11">
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 _
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-e">
                 map
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 _
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 +
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 1
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cfa8020315317-12">
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 }
                </span>
               </div>
               <div class="crayon-line" id="crayon-576861e76cfa8020315317-13">
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 }
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-576861e76cfa8020315317-14">
                <span class="crayon-sy">
                 }
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0039 seconds] -->
        <p>
        </p>
        <h2>
         根据场景选择框架或工具
        </h2>
        <p>
         比起Java庞大的社区，以及它提供的浩如烟海般的技术栈，Scala技术栈差不多可以说是沧海一粟。然而，麻雀虽小却五脏俱全，何况Scala以及Scala技术栈仍然走在迈向成熟的道路上。对于Scala程序员而言，因为项目的不同，未必能涉猎所有技术栈，而且针对不同的方面，也有多个选择。在选择这些框架或工具时，应根据实际的场景做出判断。为稳妥起见，最好能运用技术矩阵地方式对多个方案进行设计权衡与决策。
        </p>
        <p>
         我们也不能固步自封，视Java社区而不顾。毕竟那些Java框架已经经历了千锤百炼，并有许多成功的案例作为佐证。关注Scala技术栈，却又不局限自己的视野，量力而为，选择合适的技术方案，才是设计与开发的正道。
        </p>
        <h2>
         作者简介
        </h2>
        <p>
         <img src="http://cdn3.infoqstatic.com/resource/articles/scala-technology/zh/resources/0828018.jpg"/>
         <strong>
          张逸
         </strong>
         ，现为ThoughtWorks Lead Consultant。作为一名咨询师，主要为客户提供组织的敏捷转型、过程改进、企业系统架构、领域驱动设计、大数据、代码质量提升、测试驱动开发等咨询与培训工作。
        </p>
       </div>
       <p>
       </p>
       <div align="left">
        <span style="font-family: Arial, sans-serif;">
         From : InfoQ
        </span>
       </div>
       <div align="left">
       </div>
      </div>
      <div>
       <strong>
        注：转载文章均来自于公开网络，仅供学习使用，不会用于任何商业用途，如果侵犯到原作者的权益，请您与我们联系删除或者授权事宜，联系邮箱：contact@dataunion.org。转载数盟网站文章请注明原文章作者，否则产生的任何版权纠纷与数盟无关。
       </strong>
      </div>
      <!--content_text-->
      <div class="fenxian">
       <!-- JiaThis Button BEGIN -->
       <div class="jiathis_style_32x32">
        <p class="jiathis_button_weixin">
        </p>
        <p class="jiathis_button_tsina">
        </p>
        <p class="jiathis_button_qzone">
        </p>
        <p class="jiathis_button_cqq">
        </p>
        <p class="jiathis_button_tumblr">
        </p>
        <a class="jiathis jiathis_txt jtico jtico_jiathis" href="http://www.jiathis.com/share" target="_blank">
        </a>
        <p class="jiathis_counter_style">
        </p>
       </div>
       <!-- JiaThis Button END -->
      </div>
     </article>
     <!--content-->
     <!--相关文章-->
     <div class="xianguan">
      <div class="xianguantitle">
       相关文章！
      </div>
      <ul class="pic">
       <li>
        <a href="http://dataunion.org/19821.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/06/t01bf89c135830d3ad1_副本.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/19821.html" rel="bookmark" title="多面编程语言Scala">
         多面编程语言Scala
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/14967.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/04/t01650ccee12943ac2b-300x202.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/14967.html" rel="bookmark" title="为Java程序员编写的Scala的入门教程">
         为Java程序员编写的Scala的入门教程
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/6326.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/01/QQ截图20150106181250.png"/>
        </a>
        <a class="link" href="http://dataunion.org/6326.html" rel="bookmark" title="Twitter的工程师出品：scala学习指南">
         Twitter的工程师出品：scala学习指南
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/2785.html">
         <img src="http://dataunion.org/wp-content/uploads/2014/11/u1746614582929527462fm23gp0_副本.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/2785.html" rel="bookmark" title="Scala更适合用于大数据处理和机器学习">
         Scala更适合用于大数据处理和机器学习
        </a>
       </li>
      </ul>
     </div>
     <!--相关文章-->
     <div class="comment" id="comments">
      <!-- You can start editing here. -->
      <!-- If comments are open, but there are no comments. -->
      <div class="title">
       期待你一针见血的评论，Come on！
      </div>
      <div id="respond">
       <p>
        不用想啦，马上
        <a href="http://dataunion.org/wp-login.php?redirect_to=http%3A%2F%2Fdataunion.org%2F2788.html">
         "登录"
        </a>
        发表自已的想法.
       </p>
      </div>
     </div>
     <!-- .nav-single -->
    </div>
    <!--Container End-->
    <aside id="sitebar">
     <div class="sitebar_list2">
      <div class="wptag">
       <span class="tagtitle">
        热门标签+
       </span>
       <div class="tagg">
        <ul class="menu" id="menu-%e5%8f%8b%e6%83%85%e9%93%be%e6%8e%a5">
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1605" id="menu-item-1605">
          <a href="http://taidizh.com/">
           泰迪智慧
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-20884" id="menu-item-20884">
          <a href="http://www.transwarp.cn/">
           星环科技
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-3538" id="menu-item-3538">
          <a href="http://datall.org/">
           珈和遥感
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-20888" id="menu-item-20888">
          <a href="http://www.chinahadoop.cn/">
           小象学院
          </a>
         </li>
        </ul>
       </div>
      </div>
     </div>
     <div class="sitebar_list">
      <div class="textwidget">
       <div align="center">
        <a href="http://study.163.com/course/courseMain.htm?courseId=991022" target="_blank">
         <img src="http://dataunion.org/wp-content/uploads/2016/03/dv.jpg"/>
        </a>
       </div>
      </div>
     </div>
     <div class="sitebar_list">
      <h4 class="sitebar_title">
       文章分类
      </h4>
      <div class="tagcloud">
       <a class="tag-link-44" href="http://dataunion.org/category/industry/demo" style="font-size: 10.204724409449pt;" title="4个话题">
        Demo展示
       </a>
       <a class="tag-link-31" href="http://dataunion.org/category/experts" style="font-size: 15.826771653543pt;" title="52个话题">
        专家团队
       </a>
       <a class="tag-link-870" href="http://dataunion.org/category/tech/ai" style="font-size: 19.795275590551pt;" title="273个话题">
        人工智能
       </a>
       <a class="tag-link-488" href="http://dataunion.org/category/%e5%8a%a0%e5%85%a5%e6%95%b0%e7%9b%9f" style="font-size: 8pt;" title="1个话题">
        加入数盟
       </a>
       <a class="tag-link-869" href="http://dataunion.org/category/tech/viz" style="font-size: 17.204724409449pt;" title="93个话题">
        可视化
       </a>
       <a class="tag-link-30" href="http://dataunion.org/category/partners" style="font-size: 10.645669291339pt;" title="5个话题">
        合作伙伴
       </a>
       <a class="tag-link-889" href="http://dataunion.org/category/parterc" style="font-size: 11.582677165354pt;" title="8个话题">
        合作会议
       </a>
       <a class="tag-link-104" href="http://dataunion.org/category/books" style="font-size: 12.96062992126pt;" title="15个话题">
        图书
       </a>
       <a class="tag-link-220" href="http://dataunion.org/category/tech/base" style="font-size: 19.850393700787pt;" title="281个话题">
        基础架构
       </a>
       <a class="tag-link-219" href="http://dataunion.org/category/tech/analysis" style="font-size: 19.409448818898pt;" title="232个话题">
        数据分析
       </a>
       <a class="tag-link-887" href="http://dataunion.org/category/tech/dm" style="font-size: 13.291338582677pt;" title="17个话题">
        数据挖掘
       </a>
       <a class="tag-link-34" href="http://dataunion.org/category/tech" style="font-size: 20.732283464567pt;" title="404个话题">
        文章
       </a>
       <a class="tag-link-1" href="http://dataunion.org/category/uncategorized" style="font-size: 22pt;" title="693个话题">
        未分类
       </a>
       <a class="tag-link-4" href="http://dataunion.org/category/events" style="font-size: 14.503937007874pt;" title="29个话题">
        活动
       </a>
       <a class="tag-link-890" href="http://dataunion.org/category/tech/%e6%b7%b1%e5%ba%a6%e5%ad%a6%e4%b9%a0" style="font-size: 10.204724409449pt;" title="4个话题">
        深度学习
       </a>
       <a class="tag-link-221" href="http://dataunion.org/category/tech/devl" style="font-size: 18.968503937008pt;" title="193个话题">
        编程语言
       </a>
       <a class="tag-link-888" href="http://dataunion.org/category/career" style="font-size: 15.661417322835pt;" title="48个话题">
        职业规划
       </a>
       <a class="tag-link-5" href="http://dataunion.org/category/jobs" style="font-size: 14.11811023622pt;" title="25个话题">
        职位
       </a>
       <a class="tag-link-871" href="http://dataunion.org/category/industry" style="font-size: 15.716535433071pt;" title="49个话题">
        行业
       </a>
       <a class="tag-link-613" href="http://dataunion.org/category/industry/case" style="font-size: 16.984251968504pt;" title="84个话题">
        行业应用
       </a>
       <a class="tag-link-885" href="http://dataunion.org/category/industry/news" style="font-size: 17.425196850394pt;" title="102个话题">
        行业资讯
       </a>
       <a class="tag-link-10" href="http://dataunion.org/category/training" style="font-size: 14.228346456693pt;" title="26个话题">
        课程
       </a>
       <a class="tag-link-16" href="http://dataunion.org/category/sources" style="font-size: 15.661417322835pt;" title="48个话题">
        资源
       </a>
      </div>
     </div>
     <div class="sitebar_list">
      <h4 class="sitebar_title">
       功能
      </h4>
      <ul>
       <li>
        <a href="http://dataunion.org/wp-login.php?action=register">
         注册
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/wp-login.php">
         登录
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/feed">
         文章
         <abbr title="Really Simple Syndication">
          RSS
         </abbr>
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/comments/feed">
         评论
         <abbr title="Really Simple Syndication">
          RSS
         </abbr>
        </a>
       </li>
       <li>
        <a href="https://cn.wordpress.org/" title="基于WordPress，一个优美、先进的个人信息发布平台。">
         WordPress.org
        </a>
       </li>
      </ul>
     </div>
    </aside>
    <div class="clear">
    </div>
   </div>
   <!--main-->
   ﻿
   <footer id="dibu">
    <div class="about">
     <div class="right">
      <ul class="menu" id="menu-%e5%ba%95%e9%83%a8%e8%8f%9c%e5%8d%95">
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-18024" id="menu-item-18024">
        <a href="http://dataunion.org/category/partners">
         合作伙伴
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-20881" id="menu-item-20881">
        <a href="http://dataunion.org/contribute">
         文章投稿
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20872" id="menu-item-20872">
        <a href="http://dataunion.org/category/%e5%8a%a0%e5%85%a5%e6%95%b0%e7%9b%9f">
         加入数盟
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-22441" id="menu-item-22441">
        <a href="http://dataunion.org/f-links">
         友情链接
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-20874" id="menu-item-20874">
        <a href="http://dataunion.org/aboutus">
         关于数盟
        </a>
       </li>
      </ul>
      <p class="banquan">
       数盟社区        ，
        做最棒的数据科学社区
      </p>
     </div>
     <div class="left">
      <ul class="bottomlist">
       <li>
        <a href="http://weibo.com/DataScientistUnion  " target="_blank" 　title="">
         <img src="http://dataunion.org/wp-content/themes/yzipi/images/weibo.png"/>
        </a>
       </li>
       <li>
        <a class="cd-popup-trigger" href="http://dataunion.org/2788.html#0">
         <img src="http://dataunion.org/wp-content/themes/yzipi/images/weixin.png"/>
        </a>
       </li>
      </ul>
      <div class="cd-popup">
       <div class="cd-popup-container">
        <h1>
         扫描二维码,加微信公众号
        </h1>
        <img src="http://dataunion.org/wp-content/themes/yzipi/images/2014-12-06-1515289049.png"/>
        <a class="cd-popup-close" href="http://dataunion.org/2788.html">
        </a>
       </div>
       <!-- cd-popup-container -->
      </div>
      <!-- cd-popup -->
     </div>
    </div>
    <!--about-->
    <div class="bottom">
     <a href="http://dataunion.org/">
      数盟社区
     </a>
     <a href="http://www.miitbeian.gov.cn/" rel="external nofollow" target="_blank">
      京ICP备14026740号
     </a>
     联系我们：
     <a href="mailto:contact@dataunion.org" target="_blank">
      contact@dataunion.org
     </a>
     <div class="tongji">
     </div>
     <!--bottom-->
     <div class="scroll" id="scroll" style="display:none;">
      ︿
     </div>
    </div>
   </footer>
   <!--dibu-->
  </div>
 </body>
</html>